﻿#!/usr/bin/env python3

def square(n):
    for i in range(n):
        yield i**2

def square2(n):
    yield from [x*x for x in range(n)]

def main():
    '''
generator function -
使用yield语句,
    yield expr
    or 
    yield from iterable
    '''
    print(main.__doc__)
    sq = square(6)
    print(type(sq))
    print(sq.__next__())
    print(sq.__next__())
    print(list(sq))
    sq2 = square2(10)
    print(list(sq2))


if __name__=='__main__':
    main()
